package com.hongdee.help.by.controller;

import com.hongdee.help.by.service.ITaskByService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 本模块主要用于CRM实施过程中有关保养的遇到的某些问题，
 * 可通过接口一键进行处理
 */
@RestController
@RequestMapping("/help/by")
public class TaskByController {

    @Autowired
    private ITaskByService taskByService;

    /**
     * 指定公司生成新车首月任务
     * @param uid
     * @param token
     * @param startTime
     * @param endTime
     * @param companyId
     * @return
     * @throws Exception
     */
    @RequestMapping("/create/task/newcar")
    @ResponseBody
    public Map createNewCar(@RequestParam(name = "uid", defaultValue = "") String uid,
                            @RequestParam(name = "token", defaultValue = "") String token,
                            @RequestParam(name = "startTime", defaultValue = "") String startTime,
                            @RequestParam(name = "endTime", defaultValue = "") String endTime,
                            @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskByService.createNewCarFirstMonthTask(companyId,startTime,endTime);
        map.put("success","true");
        map.put("msg","生成指定公司新车首月任务完成!!");
        return map;
    }

    /**
     * 指定公司生成首保任务
     * @param uid
     * @param token
     * @param startTime
     * @param endTime
     * @param companyId
     * @return
     * @throws Exception
     */
    @RequestMapping("/create/task/sb")
    @ResponseBody
    public Map createSb(@RequestParam(name = "uid", defaultValue = "") String uid,
                            @RequestParam(name = "token", defaultValue = "") String token,
                            @RequestParam(name = "startTime", defaultValue = "") String startTime,
                            @RequestParam(name = "endTime", defaultValue = "") String endTime,
                            @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskByService.createSbTask(companyId,startTime,endTime);
        map.put("success","true");
        map.put("msg","生成指定公司首保任务完成!!");
        return map;
    }

    /**
     * 指定公司生成二保任务
     * @param uid
     * @param token
     * @param startTime
     * @param endTime
     * @param companyId
     * @return
     * @throws Exception
     */
    @RequestMapping("/create/task/eb")
    @ResponseBody
    public Map createEb(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token,
                        @RequestParam(name = "startTime", defaultValue = "") String startTime,
                        @RequestParam(name = "endTime", defaultValue = "") String endTime,
                        @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskByService.createEbTask(companyId,startTime,endTime);
        map.put("success","true");
        map.put("msg","生成指定公司二保任务完成!!");
        return map;
    }

    /**
     * 指定公司生成定保任务
     * @param uid
     * @param token
     * @param startTime
     * @param endTime
     * @param companyId
     * @return
     * @throws Exception
     */
    @RequestMapping("/create/task/db")
    @ResponseBody
    public Map createDb(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token,
                        @RequestParam(name = "startTime", defaultValue = "") String startTime,
                        @RequestParam(name = "endTime", defaultValue = "") String endTime,
                        @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskByService.createDbTask(companyId,startTime,endTime);
        map.put("success","true");
        map.put("msg","生成指定公司定保任务完成!!");
        return map;
    }

    /**
     * 指定公司生成保养任务
     * @param uid
     * @param token
     * @param startTime
     * @param endTime
     * @param companyId
     * @return
     * @throws Exception
     */
    @RequestMapping("/create/task/by")
    @ResponseBody
    public Map createTask(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token,
                        @RequestParam(name = "startTime", defaultValue = "") String startTime,
                        @RequestParam(name = "endTime", defaultValue = "") String endTime,
                        @RequestParam(name = "companyId", defaultValue = "") String companyId) throws Exception {
        Map map=new HashMap();
        taskByService.createByTask(companyId,startTime,endTime);
        map.put("success","true");
        map.put("msg","生成指定公司保养任务完成!!");
        return map;
    }

}
